package com.mengxiangnongfu.controller.advice;

import com.mengxiangnongfu.vo.AjaxResult;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.MethodParameter;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.server.ServerHttpRequest;
import org.springframework.http.server.ServerHttpResponse;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice;


/**
 * @author Yang
 * @version 1.0
 * @date 2020/10/3 0:01
 */
@ControllerAdvice(basePackages = "com.mengxiangnongfu.controller.system.*")
@Slf4j
public class MyResponseBodyAdvice implements ResponseBodyAdvice<AjaxResult> {

    @Override
    public boolean supports(MethodParameter methodParameter, Class aClass) {
        return false;
    }


    @SneakyThrows
    @Override
    public AjaxResult beforeBodyWrite(AjaxResult ajaxResult, MethodParameter methodParameter, MediaType mediaType, Class<? extends HttpMessageConverter<?>> aClass, ServerHttpRequest serverHttpRequest, ServerHttpResponse serverHttpResponse) {
        log.debug(serverHttpResponse.getBody().toString());
        return ajaxResult;
    }

}
